﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;

namespace PowerControl.Services
{
    public class Power
    {
        public Power()
        {

        }
        /// <summary>
        /// 购买电数据域加密
        /// </summary>
        /// <param name="Power">电量</param>
        /// <param name="PowerCount">够点次数</param>
        /// <returns>byte</returns>
        public byte[] PayPower(decimal Power, int PowerCount)
        {

            byte[] sendBuf = new byte[5];

            int Count1 = PowerCount % 100;
            int Count0 = PowerCount / 100;
            byte x0;
            byte x1;

            x0 = (byte)Convert.ToInt16(Count1.ToString(), 16);//购电次数2字节


            x1 = (byte)Convert.ToInt16(Count0.ToString(), 16);//购电次数2字节

            byte x4 = (byte)Convert.ToInt16(Convert.ToString(Math.Abs((Power / 100))).Split('.')[0], 16);//购电量3字节
            byte x3 = (byte)Convert.ToInt16(Convert.ToString((Math.Abs(Power) % 100)).Split('.')[0], 16);
            byte x2 = (byte)Convert.ToInt16((Power.ToString().Substring(Power.ToString().IndexOf('.') + 1)), 16);
            int off = 0;
            sendBuf[off++] = (byte)(x0 + 0x33);
            sendBuf[off++] = (byte)(x1 + 0x33);
            sendBuf[off++] = (byte)(x2 + 0x33); //
            sendBuf[off++] = (byte)(x3 + 0x33);
            sendBuf[off++] = (byte)(x4 + 0x33);

            return sendBuf;
        }
        private int qrand()
        {
            Random rand = new Random();
            int randNumber = rand.Next(10, 99);


            return randNumber;

            //return (char)char.Parse((Convert.ToString(randNumber, 16)));
        }

        private byte LOBYTE(int d)
        {


            string mm = d.ToString().Substring(d.ToString().Length - 2);
            return (byte)int.Parse(mm);

        }


        private byte HIBYTE(int d)
        {

            string mm = d.ToString().Substring(d.ToString().Length - 4, 2);
            return (byte)int.Parse(mm);

        }

        /// <summary>
        /// 把十进制 转为8421BCD码
        /// </summary>
        /// <param name="paramLan"></param>
        /// <returns></returns>
        public int BintoBcd(int paramLan)
        {
            return ((paramLan / 10) << 4 + ((paramLan % 10) & 0x0f));   //把十进制转为8421BCD码.

            //return paramLan;         


        }

        /// <summary>
        /// 密码加密转byte
        /// </summary>
        /// <param name="pwd">密码</param>
        /// <returns>byte</returns>
        public byte[] pwdbyte(string pwd)
        {
            byte[] pwd1byte = new byte[4];

            pwd1byte[0] = (byte)(Convert.ToInt16(pwd.Substring(pwd.Length - 2), 16) + 0x33);
            pwd1byte[1] = (byte)(Convert.ToInt16(pwd.Substring(pwd.Length - 4, 2), 16) + 0x33);
            pwd1byte[2] = (byte)(Convert.ToInt16(pwd.Substring(pwd.Length - 6, 2), 16) + 0x33);
            pwd1byte[3] = (byte)(Convert.ToInt16(pwd.Substring(0, 2), 16) + 0x33);
            return pwd1byte;
        }

        /// <summary>
        /// 电表编号转byte
        /// </summary>
        /// <param name="PowerNo">电表编号</param>
        /// <returns>byte</returns>
        public byte[] PowerNobyte(string PowerNo)
        {
            byte[] pwd1byte = new byte[6];

            if (PowerNo.Length < 10)
            {

                pwd1byte[0] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 2), 16));
                pwd1byte[1] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 4, 2), 16));
                pwd1byte[2] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 6, 2), 16));
                pwd1byte[3] = (byte)(Convert.ToInt16(PowerNo.Substring(0, 2), 16));
                pwd1byte[4] = (byte)(0x00);
                pwd1byte[5] = (byte)(0x00);
            }
            else if (PowerNo.Length < 12)
            {
                pwd1byte[0] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 2), 16));
                pwd1byte[1] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 4, 2), 16));
                pwd1byte[2] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 6, 2), 16));
                pwd1byte[3] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 8, 2), 16));
                pwd1byte[4] = (byte)(Convert.ToInt16(PowerNo.Substring(0, 2), 16));
                pwd1byte[5] = (byte)(0x00);
            }
            else
            {
                pwd1byte[0] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 2), 16));
                pwd1byte[1] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 4, 2), 16));
                pwd1byte[2] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 6, 2), 16));
                pwd1byte[3] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 8, 2), 16));
                pwd1byte[4] = (byte)(Convert.ToInt16(PowerNo.Substring(PowerNo.Length - 10, 2), 16));
                pwd1byte[5] = (byte)(Convert.ToInt16(PowerNo.Substring(0, 2), 16));
            }
            return pwd1byte;
        }

        /// <summary>
        /// 取得 从地址位后的 68开始到 校验码之前的 模 取不大于256的值
        /// </summary>
        /// <param name="all">byte[]</param>
        /// <returns>byte</returns>
        public byte getmol(byte[] all)
        {
            byte mol;
            int aa = 0;
            for (int i = 0; i < all.Length; i++)
            {

                aa += all[i];
            }
            mol = (byte)(aa % 256);
            return mol;
        }


        public byte[] getOpera(string optea)
        {
            byte[] opera = new byte[2];

            opera[0] = (byte)(Convert.ToInt16(optea.Substring(optea.Length - 2), 16) + 0x33);
            opera[1] = (byte)(Convert.ToInt16(optea.Substring(0, 2), 16) + 0x33);
            return opera;
        }

        /// <summary>
        /// 获取功率byte
        /// </summary>
        /// <param name="kw">功率（kw）</param>
        /// <returns>byte</returns>
        public byte[] getkw(string kw)
        {
            byte[] kw1 = new byte[2];
            string[] aa = kw.Split('.');

            kw1[0] = (byte)(Convert.ToInt16(aa[1], 16) + 0x33);
            kw1[1] = (byte)(Convert.ToInt16(aa[0], 16) + 0x33);
            return kw1;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bytestr"></param>
        /// <returns></returns>
        public string[] Get16Byte(byte[] bytestr)
        {
            string[] strbyte = new string[bytestr.Length];
            for (int i = 0; i < bytestr.Length; i++)
            {
                strbyte[i] = byteTo16string((int)bytestr[i]);
            }
            return strbyte;
        }

        /// <summary>
        /// 二进制转16进制
        /// </summary>
        /// <param name="bytestr"></param>
        /// <returns></returns>
        private string byteTo16string(int bytestr)
        {
            return Convert.ToString(bytestr, 16);
        }

        public static void WriteLog(string text)
        {

            var log = NLog.Web.NLogBuilder.ConfigureNLog($"Configs/nlog.config").GetCurrentClassLogger();

            log.Info(text);
        }

        public static void Write2(string text)
        {
            var log = NLog.Web.NLogBuilder.ConfigureNLog($"Configs/nlog.config").GetCurrentClassLogger();

            log.Info(text);
        }


        public static void WritePower(string text)
        {
            string fileName = DateTime.Now.Date.ToString("yyy-MM-dd") + "-" + DateTime.Now.Hour.ToString() + "公用电分摊.txt";


            FileStream fs = new FileStream(@"E:\Power\" + fileName, FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine("");

            sw.Close();
            fs.Close();
            StreamWriter SWNEW;
            SWNEW = File.AppendText(@"E:\Power\" + fileName);
            SWNEW.WriteLine(text + "-----------" + DateTime.Now.ToString());
            SWNEW.Close();
        }

        public static void WriteWater(string text)
        {
            string fileName = DateTime.Now.Date.ToString("yyy-MM-dd") + "-" + DateTime.Now.Hour.ToString() + "水表.txt";


            FileStream fs = new FileStream(@"E:\Power\" + fileName, FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine("");

            sw.Close();
            fs.Close();
            StreamWriter SWNEW;
            SWNEW = File.AppendText(@"E:\Power\" + fileName);
            SWNEW.WriteLine(text + "-----------" + DateTime.Now.ToString());
            SWNEW.Close();
        }


        /// <summary>
        /// 分摊公用电
        /// </summary>
        /// <param name="Cell_Id"></param>
        /// <returns></returns>
        public void cellPubShare(string Cell_Id)
        {


            string sql = "SELECT TOP 2 CPC_Id,CPC_Room_Id,CPC_Cell_Id,CPC_Active_Power,CPC_Copy_Day";
            sql += " FROM take_power_consumption";
            sql += " WHERE CPC_Active_Power IS NOT NULL AND CPC_Create_Date>='2013-09-03' AND CPC_Cell_Id=" + Cell_Id;
            sql += " ORDER BY CPC_Id DESC";
            DataTable tbPower = DBClass.GetDataTable(sql);
            // WritePower("====单元Id=刚进来====" + Cell_Id);

            //WritePower(sql);
            //WritePower(tbPower.Rows.Count.ToString());
            if (tbPower.Rows.Count > 1)
            {
                DateTime dtend = DateTime.Parse(DateTime.Parse(tbPower.Rows[0]["CPC_Copy_Day"].ToString()).ToString("yyyy-MM-dd"));
                //WritePower("dtend:" + dtend.ToString());
                DateTime dtstart = DateTime.Parse(DateTime.Parse(tbPower.Rows[1]["CPC_Copy_Day"].ToString()).ToString("yyyy-MM-dd"));
                TimeSpan ts = dtend.Subtract(dtstart);
                //WritePower("结束时间:" + dtend.ToString());
                //WritePower("开始时间:" + dtstart.ToString());
                //WritePower("dtstart:" + dtstart.ToString());
                int dayD_value = ts.Days;
                // WritePower("天数：" + dayD_value.ToString());

                decimal powerShare = decimal.Parse(tbPower.Rows[0]["CPC_Active_Power"].ToString()) - decimal.Parse(tbPower.Rows[1]["CPC_Active_Power"].ToString());

                if (dayD_value == 0 || powerShare <= 0)
                {
                    return;
                }
                powerShare = powerShare / dayD_value;
                // WritePower("====单元Id=" + Cell_Id + "=======分摊额：=" + powerShare + "======应分摊天数：=" + dayD_value.ToString());
                DateTime createdate1 = DateTime.Now;
                for (int i = 0; i < dayD_value; i++)
                {
                    dtstart = dtstart.AddDays(i);
                    sql = "SELECT ROM_Public_Sharing_Power,Room.ROM_Id FROM Room";
                    sql += " INNER JOIN Contract ON Contract.ROM_Id=Room.ROM_Id AND CUC_Id=" + Cell_Id;
                    sql += " WHERE CO_State=0 AND CO_Expire_Date>='" + dtstart.ToString() + "' and CO_Start_Date<='" + dtstart.ToString() + "'";
                    DataTable tb = DBClass.GetDataTable(sql);
                    //WritePower("取得有效合同:" + sql);
                    //WritePower(tb.Rows.Count.ToString());

                    decimal room_Power = 0.00M;
                    if (tb.Rows.Count > 0)
                        room_Power = powerShare / tb.Rows.Count;


                    for (int j = 0; j < tb.Rows.Count; j++)
                    {
                        if (!string.IsNullOrEmpty(tb.Rows[j]["ROM_Public_Sharing_Power"].ToString()))
                        {

                            // WritePower("==公用电分摊====ROM_Id=" + tb.Rows[j]["ROM_Id"].ToString() + "======分摊前公共电余额=" + tb.Rows[j]["ROM_Public_Sharing_Power"].ToString() + "=====分摊额度:=" + room_Power + "=====单元号：=" + Cell_Id);

                            decimal powerPoint = (decimal.Parse(tb.Rows[j]["ROM_Public_Sharing_Power"].ToString()) - room_Power); //剩余 公用电量

                            sql = "Update Room SET ROM_Public_Sharing_Power=" + powerPoint;
                            sql += " WHERE ROM_Id=" + tb.Rows[j]["ROM_Id"].ToString();
                            DBClass.ExeNonQuery(sql);

                            //WritePower("===powerPoint===" + powerPoint.ToString());





                            //进行 电费扣取
                            if (powerPoint < 0 && i == dayD_value - 1)
                            {
                                sql = "SELECT TOP 1 CPC_Id,CPC_Remain_Power_Consumption FROM take_power_consumption WHERE CPC_Room_Id=" + tb.Rows[j]["ROM_Id"].ToString() + " AND CONVERT(Varchar(20),[CPC_Create_Date],112)=CONVERT(Varchar(20),getdate(),112) AND CPC_Remain_Power_Consumption IS NOT NULL";
                                DataTable tbpowerRe = DBClass.GetDataTable(sql);
                                decimal remainPower = 0.0M; //公用电配额
                                decimal roomremainPower = 0.0M;//房间应该充入电费额
                                decimal powerRemain = 0.0M; //房间剩余电量
                                decimal publicrommRemian = 0.0M;//中间变量
                                if (tbpowerRe.Rows.Count > 0 && decimal.Parse(tbpowerRe.Rows[0]["CPC_Remain_Power_Consumption"].ToString()) > 0)
                                {
                                    remainPower = 0.0M; //公用电配额
                                    roomremainPower = 0.0M;//房间应该充入电费额
                                    powerRemain = decimal.Parse(tbpowerRe.Rows[0]["CPC_Remain_Power_Consumption"].ToString()); //房间剩余电量
                                    publicrommRemian = 0.0M;//中间变量

                                    //WritePower("++++++powerRemain电表剩余房间+++++:"+powerRemain.ToString());
                                    // WritePower("============Appsetting.first:=========" + Appsetting.first.ToString());
                                    if (powerRemain < Appsetting.first)
                                    {
                                        remainPower = powerRemain + powerPoint;
                                    }
                                    else
                                    {
                                        remainPower = (powerRemain - Appsetting.first) * Appsetting.percentage + Appsetting.first + powerPoint;
                                        roomremainPower = powerRemain - Appsetting.first - ((powerRemain - Appsetting.first) * Appsetting.percentage);
                                        if (remainPower > Appsetting.second)
                                        {
                                            roomremainPower = roomremainPower + (remainPower - Appsetting.second);
                                            remainPower = Appsetting.second;

                                        }

                                    }
                                    //WritePower("<<<<<<<<<remainPower>>>>>>>>>>>>>>>>>>" + remainPower.ToString());
                                    sql = "UPDATE take_power_consumption SET CPC_Remain_Power_Consumption=" + roomremainPower + " WHERE CPC_Id=" + tbpowerRe.Rows[0]["CPC_Id"].ToString();

                                    DBClass.ExecuteNonQuery(sql);

                                    createCmd(roomremainPower, tb.Rows[j]["ROM_Id"].ToString());
                                    powerPoint = remainPower;


                                }
                                sql = "Update Room SET ROM_Public_Sharing_Power=" + remainPower;
                                sql += " WHERE ROM_Id=" + tb.Rows[j]["ROM_Id"].ToString();
                                DBClass.ExeNonQuery(sql);


                            }
                            int kk = 0 - (dayD_value - 1 - i);

                            if (i == dayD_value - 1)
                            {
                                sql = "INSERT INTO take_power_consumption (CPC_Room_Id,CPC_Create_Date,CPC_PubRemain,CPC_Pubshaw) VALUES(" + tb.Rows[j]["ROM_Id"].ToString() + ",'" + createdate1.AddDays(kk).ToString() + "',";
                                sql += powerPoint + "," + room_Power + ")";
                            }
                            else
                            {
                                sql = "INSERT INTO take_power_consumption (CPC_Room_Id,CPC_Create_Date,CPC_PubRemain,CPC_Pubshaw) VALUES(" + tb.Rows[j]["ROM_Id"].ToString() + ",'" + createdate1.AddDays(kk).ToString() + "',";
                                sql += powerPoint + "," + room_Power + ")";
                            }
                            DBClass.ExeNonQuery(sql);

                        }
                    }
                }

                //if (DateTime.Now.Day == 1)
                //{
                //    sql = "SELECT CO_Id,ROM_Id,CUT_Id,CO_Pub_Power FROM Contract";
                //    sql += " INNER JOIN Room ON Contract.ROM_Id=Room.ROM_Id AND CUC_Id=" + Cell_Id;
                //    sql += " WHERE CO_State=0 AND CO_Pub_Power<0";
                //    DataTable tb123 = DBClass.GetDataTable(sql);
                //    perWeek(tb123);

                //}
            }
        }




        /// <summary>
        /// 写入电量
        /// </summary>
        /// <param name="powerRoom"></param>
        /// <param name="room_Id"></param>

        public void createActivePower(string room_Id)
        {
            string sql = "SELECT  CPC_Id,CPC_Room_Id,CPC_Cell_Id,CPC_Active_Power,CPC_Copy_Day";
            sql += " FROM take_power_consumption";
            sql += " WHERE CPC_Active_Power IS NOT NULL AND CPC_Create_Date>='2013-09-03' AND CPC_Room_Id=" + room_Id;
            sql += " ORDER BY CPC_Copy_Day DESC limit 2";
            DataTable tbPower = DBClass.GetDataTable(sql);
            if (tbPower.Rows.Count > 1)
            {
                DateTime dtend = DateTime.Parse(DateTime.Parse(tbPower.Rows[0]["CPC_Copy_Day"].ToString()).ToString("yyyy-MM-dd"));
                //WritePower("dtend:" + dtend.ToString());
                DateTime dtstart = DateTime.Parse(DateTime.Parse(tbPower.Rows[1]["CPC_Copy_Day"].ToString()).ToString("yyyy-MM-dd"));
                TimeSpan ts = dtend.Subtract(dtstart);
                string Rom_Id = tbPower.Rows[0]["CPC_Room_Id"].ToString();
                int dayD_value = ts.Days;
                decimal powerShare = decimal.Parse(tbPower.Rows[0]["CPC_Active_Power"].ToString()) - decimal.Parse(tbPower.Rows[1]["CPC_Active_Power"].ToString());

                if (dayD_value != 0)
                {
                    powerShare = powerShare / dayD_value;
                    DateTime createdate1 = DateTime.Now;
                    decimal aa = decimal.Parse(tbPower.Rows[1]["CPC_Active_Power"].ToString());
                    for (int i = 0; i < dayD_value; i++)
                    {

                        int kk = 0 - (dayD_value - 1 - i);

                        if (i != dayD_value - 1)
                        {

                            ////sql = "INSERT INTO take_power_consumption (CPC_Room_Id,CPC_Cell_Id,CPC_Active_Power,CPC_Copy_Day) VALUES(";
                            ////sql += Rom_Id + "," + Cell_Id + "," + Power1 + ",'" + DateTime.Now.ToString() + "')";
                            ////DBClass.ExecuteNonQuery(sql);
                            //    }
                            //    else
                            //    {
                            aa += powerShare;
                            sql = "INSERT INTO take_power_consumption (CPC_Room_Id,CPC_Active_Power,CPC_Copy_Day,CPC_Create_Date) VALUES(";
                            sql += Rom_Id + "," + aa + ",'" + createdate1.AddDays(kk).ToString() + "','" + createdate1.AddDays(kk).ToString() + "')";
                            DBClass.ExecuteNonQuery(sql);

                        }

                    }
                }
            }



        }


        /// <summary>
        /// 电费抵扣充值
        /// </summary>
        /// <param name="powerroom"></param>
        /// <param name="room_Id"></param>
        private void createCmd(decimal powerroom, string room_Id)
        {
            string sql = "SELECT MB_No,MB_Pwd,MC_No,Meter_Box.MB_Id FROM Meter_Box";
            sql += " INNER JOIN Room ON Room.MB_Id=Meter_Box.MB_Id AND ROM_Id=" + room_Id;
            sql += " INNER JOIN Customer_Cell ON Room.CUC_Id=Customer_Cell.CUC_Id";
            sql += " INNER JOIN Meter_Collector ON Meter_Collector.MC_Id=Customer_Cell.MC_Id";
            DataTable tb = DBClass.GetDataTable(sql);

            // WritePower("命令行数:"+sql);

            if (tb.Rows.Count > 0 && powerroom > 0)
            {
                sql = "INSERT INTO Meter_Operation (MO_MC_No,MO_MB_Id,MO_MB_No,MO_Room_Id,MO_Operation,MO_Power_Count,MO_Power_Consumption,MO_Type,MO_State,MO_Pwd,MO_Create_Date,MO_Flag) VALUES('";
                sql += tb.Rows[0]["MC_No"].ToString() + "'," + tb.Rows[0]["MB_Id"].ToString() + ",'" + tb.Rows[0]["MB_No"].ToString() + "'," + room_Id + ",'C03E',0,0.00,8,0,'" + tb.Rows[0]["MB_Pwd"].ToString() + "','";
                sql += DateTime.Now.ToString() + "',1);";

                sql += "INSERT INTO Meter_Operation (MO_MC_No,MO_MB_Id,MO_MB_No,MO_Room_Id,MO_Operation,MO_Power_Count,MO_Power_Consumption,MO_Type,MO_State,MO_Pwd,MO_Create_Date,MO_Flag) VALUES('";
                sql += tb.Rows[0]["MC_No"].ToString() + "'," + tb.Rows[0]["MB_Id"].ToString() + ",'" + tb.Rows[0]["MB_No"].ToString() + "'," + room_Id + ",'E500',9999,9999.99,6,0,'" + tb.Rows[0]["MB_Pwd"].ToString() + "','";
                sql += DateTime.Now.ToString() + "',1);";


                sql += "INSERT INTO Meter_Operation (MO_MC_No,MO_MB_Id,MO_MB_No,MO_Room_Id,MO_Operation,MO_Power_Count,MO_Power_Consumption,MO_Type,MO_State,MO_Pwd,MO_Create_Date,MO_Flag) VALUES('";
                sql += tb.Rows[0]["MC_No"].ToString() + "'," + tb.Rows[0]["MB_Id"].ToString() + ",'" + tb.Rows[0]["MB_No"].ToString() + "'," + room_Id + ",'E500',1," + powerroom + ",0,0,'" + tb.Rows[0]["MB_Pwd"].ToString() + "','";
                sql += DateTime.Now.ToString() + "',1);";

                sql += "INSERT INTO Meter_Operation (MO_MC_No,MO_MB_Id,MO_MB_No,MO_Room_Id,MO_Operation,MO_Power_Count,MO_Power_Consumption,MO_Type,MO_State,MO_Pwd,MO_Create_Date,MO_Flag) VALUES('";
                sql += tb.Rows[0]["MC_No"].ToString() + "'," + tb.Rows[0]["MB_Id"].ToString() + ",'" + tb.Rows[0]["MB_No"].ToString() + "'," + room_Id + ",'C03F',0,0.00,9,0,'" + tb.Rows[0]["MB_Pwd"].ToString() + "','";
                sql += DateTime.Now.ToString() + "',1)";

                //sql = "INSERT INTO Meter_Operation (MO_MC_No,MO_MB_Id,MO_MB_No,MO_Room_Id,MO_Operation,MO_Power_Count,MO_Power_Consumption,MO_Type,MO_State,MO_Pwd,MO_Create_Date,MO_Flag) VALUES('";
                //sql += tb.Rows[0]["MC_No"].ToString() + "'," + tb.Rows[0]["MB_Id"].ToString() + ",'" + tb.Rows[0]["MB_No"].ToString() + "'," + room_Id + ",'E500',9999,9999.99,6,0,'" + tb.Rows[0]["MB_Pwd"].ToString() + "','";
                //sql += DateTime.Now.ToString() + "',1);";


                //sql += "INSERT INTO Meter_Operation (MO_MC_No,MO_MB_Id,MO_MB_No,MO_Room_Id,MO_Operation,MO_Power_Count,MO_Power_Consumption,MO_Type,MO_State,MO_Pwd,MO_Create_Date,MO_Flag) VALUES('";
                //sql += tb.Rows[0]["MC_No"].ToString() + "'," + tb.Rows[0]["MB_Id"].ToString() + ",'" + tb.Rows[0]["MB_No"].ToString() + "'," + room_Id + ",'E500',1," + powerroom + ",0,0,'" + tb.Rows[0]["MB_Pwd"].ToString() + "','";
                //sql += DateTime.Now.ToString() + "',1)";

                DBClass.ExeNonQuery(sql);
            }
        }









    }
}
